﻿Imports System.Drawing.Bitmap
Imports System.Data.OleDb
Imports System.Drawing.Imaging.ImageFormat
Imports System.Configuration
Imports System.IO.Ports
Imports System.Threading

Module Mod_SerialPort

    'Public m_ModName As String = "Mod_SerialPort"
    'Public sp_obj As SerialPortCommDll.SerialPortObject
    'Public plccmd As String = ""

    'Public plcOrderCmd() As String
    'Public plcSelectCmd As New List(Of Object)


    ''处理PLC生产线数据
    'Public Sub setPLCLineData(ByVal data As Byte())
    '    Dim plcstr As String = ""
    '    For i As Integer = 2 To data.Length - 2
    '        plcstr = plcstr + Chr(data(i))
    '    Next
    '    If (plcstr.IndexOf("F1")) Then '1号生产线数据
    '        If (plcstr <> plclinedate1) Then
    '            dealLineDate("1", plcstr)
    '            plclinedate1 = plcstr
    '        End If
    '    ElseIf (plcstr.IndexOf("F2")) Then '2号生产线数据
    '        If (plcstr <> plclinedate2) Then
    '            dealLineDate("2", plcstr)
    '            plclinedate2 = plcstr
    '        End If
    '    ElseIf (plcstr.IndexOf("F3")) Then '3号生产线数据
    '        If (plcstr <> plclinedate3) Then
    '            dealLineDate("3", plcstr)
    '            plclinedate3 = plcstr
    '        End If
    '    ElseIf (plcstr.IndexOf("F4")) Then '4号生产线数据
    '        If (plcstr <> plclinedate4) Then
    '            dealLineDate("4", plcstr)
    '            plclinedate4 = plcstr
    '        End If
    '    End If

    'End Sub

    ''检查数据是否正确
    'Public Function checkRight(ByVal data As Byte()) As Boolean
    '    If (data(0) = &H2 And data(data.Length - 1) = &H3) Then
    '        Return True
    '    Else
    '        Return False
    '    End If
    'End Function

    'Public Sub initPLCSelectCmd()
    '    plcSelectCmd.Clear()
    '    Dim a As Byte = &H2
    '    Dim b As Byte = &H80
    '    Dim c As Byte = &H3
    '    Dim F As Byte = &H46
    '    Dim temp() As Byte = {a, b, F, &H31, c}
    '    plcSelectCmd.Add(temp)
    '    Dim temp1() As Byte = {a, b, F, &H32, c}
    '    plcSelectCmd.Add(temp1)
    '    Dim temp2() As Byte = {a, b, F, &H33, c}
    '    plcSelectCmd.Add(temp2)
    '    Dim temp3() As Byte = {a, b, F, &H34, c}
    '    plcSelectCmd.Add(temp3)
    'End Sub

    ''当数据变化是进行数据调整
    'Private Sub dealLineDate(ByVal lineid As String, ByVal plcstr As String)
    '    Dim lineindex As Integer = CInt(lineid) - 1
    '    templinedata = linedata(lineindex)
    '    Dim Data() As Byte = System.Text.Encoding.Default.GetBytes(plcstr)
    '    Dim temp As String = ""
    '    For i As Integer = 0 To Data.Length - 1
    '        If (Data(i) < &H40) Then
    '            temp = temp + Chr(Data(i))
    '        Else
    '            If (Chr(Data(i)) = "D") Then
    '                temp = ""
    '            ElseIf (Chr(Data(i)) = "B") Then
    '                linedata(lineindex).stackno = CInt(temp)
    '                temp = ""
    '            ElseIf (Chr(Data(i)) = "A") Then
    '                linedata(lineindex).stacknum = CInt(temp)
    '                temp = ""
    '            ElseIf (Chr(Data(i)) = "C") Then
    '                linedata(lineindex).producesum = CInt(temp)
    '                temp = ""
    '            ElseIf (Chr(Data(i)) = "F") Then
    '                linedata(lineindex).badpartnum = CInt(temp)
    '                temp = ""
    '            End If
    '        End If
    '        Console.WriteLine(Data(i).ToString & "-----" & temp)
    '    Next
    '    linedata(lineindex).lineid = temp
    '    If (linedata(lineindex).badpartnum > templinedata.badpartnum) Then
    '        frmMain.savePicInfo(lineid, True)
    '    ElseIf (isPointStackNum(linedata(lineindex).stacknum)) Then
    '        frmMain.savePicInfo(lineid, False)
    '    End If

    'End Sub

    'Private Function isPointStackNum(ByVal stacknum As Integer) As Boolean
    '    Dim stacknumlist() As Integer = {1, 2, 103, 104}
    '    For i As Integer = 0 To stacknumlist.Length - 1
    '        If (stacknumlist(i) = stacknum) Then
    '            Return True
    '        End If
    '    Next
    '    Return False
    'End Function


    'Public Sub UpdateClearLine(ByVal data As Byte())
    '    Dim plcstr As String = ""
    '    For i As Integer = 2 To data.Length - 2
    '        plcstr = plcstr + Chr(data(i))
    '    Next
    '    Dim lineid As String = getLineID(plcstr)

    'End Sub

    'Public Function getLineID(ByVal plcstr As String) As String
    '    Dim result As String = ""
    '    If (plcstr.IndexOf("F1")) Then '1号生产线数据
    '        result = "1"
    '    ElseIf (plcstr.IndexOf("F2")) Then '2号生产线数据
    '        result = "2"
    '    ElseIf (plcstr.IndexOf("F3")) Then '3号生产线数据
    '        result = "3"
    '    ElseIf (plcstr.IndexOf("F4")) Then '4号生产线数据
    '        result = "4"
    '    End If
    '    Return result
    'End Function

End Module
